#!/usr/bin/env python3
"""
模拟本地视频生成服务
用于测试视频生成API
"""

from flask import Flask, request, jsonify
import time
import uuid
import json

app = Flask(__name__)

# 模拟任务存储
tasks = {}

@app.route('/api/video/generate', methods=['POST'])
def generate_video():
    """模拟视频生成接口"""
    try:
        data = request.get_json()
        print(f"收到视频生成请求: {data}")
        
        # 模拟处理时间
        time.sleep(3)
        
        # 生成模拟的视频URL
        video_url = f"https://example.com/videos/{uuid.uuid4()}.mp4"
        
        response = {
            "video_url": video_url,
            "status": "success",
            "message": "视频生成成功"
        }
        
        print(f"返回响应: {response}")
        return jsonify(response)
        
    except Exception as e:
        print(f"处理请求时出错: {e}")
        return jsonify({
            "error": "处理请求失败",
            "message": str(e)
        }), 500

@app.route('/health', methods=['GET'])
def health():
    """健康检查接口"""
    return jsonify({
        "status": "healthy",
        "service": "mock-video-service",
        "timestamp": time.time()
    })

if __name__ == '__main__':
    print("启动模拟视频生成服务...")
    print("服务地址: http://127.0.0.1:5000")
    print("视频生成接口: POST /api/video/generate")
    print("健康检查接口: GET /health")
    app.run(host='127.0.0.1', port=5000, debug=True)

